<p>
Step 1: Initialize the Algorithm： At the beginning of your algorithm, you need to set the start date, the end date and the cash required for the algorithm. For options algorithm, you need to add the equity and the options written on this equity.
</p>
<div class="section-example-container">

<pre class="python">def Initialize(self):
   self.SetStartDate(2016, 1, 1)
   self.SetEndDate(2016, 3, 1)
   self.SetCash(100000)
   equity = self.AddEquity("IBM", Resolution.Minute)
   option = self.AddOption("IBM", Resolution.Minute)
   self.symbol = option.Symbol
   # set our strike/expiry filter for this option chain
   option.SetFilter(-3, +3, timedelta(0), timedelta(30))
   # use the underlying equity as the benchmark
   self.SetBenchmark(equity.Symbol)
   self.call = "IBM" # Initialize the call contract
</pre>
</div>
<p>
  In the initialization process, you need to add a coarse selection for the options contracts. Here we use <code>option.SetFilter(-3, +3, timedelta(0), timedelta(60))</code> to implement the coarse selection process. If today's market price of underlying stock is $159, the strike prices of IBM options are spaced $5. Then SetFilter will look up the most at the money contract with the strike being K=$160 (Here K might not be $159 since rarely will option be ATM exactly). The filter will look for options with strikes between and including (160-5*3, 160+5*3). The time to expiration of these options is restricted within 60 days from now on.
</p>
<p>
  Step 2: Choose the Call Options Contract: Purchasing the underlying stock for 100 shares or an integer multiple of 100 shares. For options contract, one contract represents 100 shares of stock.
</p>
<p>
  Step 3: Filter out the call options from candidate contracts.
</p>
  <div class="section-example-container">
  <pre class="csharp">
  </pre>
  <pre class="python">call = [x for x in chain if x.Right == OptionRight.Call]
  </pre>
  </div>
<p>
  Step 4: Select the most ATM contract with the furthest expiration date from call options contracts. Sell this call contract for each 100 shares of stock you own. Here you can also choose ITM or OTM contract based on your expected level of profit and the level of risk you can take.
</p>
<div class="section-example-container">

<pre class="python">def TradeOptions(self,slice):
		if slice.OptionChains.Count == 0: return
    for i in slice.OptionChains:
        if i.Key != self.symbol: continue
        chain = i.Value
        call = [x for x in chain if x.Right == 0] # filter the call options contracts
        # sorted the contracts according to their expiration dates and choose the ATM options
        contracts = sorted(sorted(call, key = lambda x: abs(chain.Underlying.Price - x.Strike)),
                                        key = lambda x: x.Expiry, reverse=True)
        if len(contracts) == 0: return
        contract = contracts[0]
        self.call = contract.Symbol
        self.Sell(self.call, 1) # short the call options
        if self.Portfolio["IBM"].Quantity == 0:
            self.Buy("IBM",100)     # buy 100 the underlying stock
            self.Log("The stock price at time 0 S(0): {}".format(self.Securities["IBM"].Price))
</pre>
</div>
